/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "rack")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Rack.findAll", query = "SELECT r FROM Rack r"),
    @NamedQuery(name = "Rack.findById", query = "SELECT r FROM Rack r WHERE r.id = :id"),
    @NamedQuery(name = "Rack.findByDimension", query = "SELECT r FROM Rack r WHERE r.dimension = :dimension")})
public class Rack implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    @Column(name = "Dimension")
    private String dimension;
    @JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Component component;
    @JoinColumn(name = "ID_Isle", referencedColumnName = "ID")
    @ManyToOne
    private Isle iDIsle;
    @OneToMany(mappedBy = "idRack")
    private Collection<Server> serverCollection;
    @OneToMany(mappedBy = "iDRack")
    private Collection<Storage> storageCollection;

    public Rack() {
    }

    public Rack(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDimension() {
        return dimension;
    }

    public void setDimension(String dimension) {
        this.dimension = dimension;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    public Isle getIDIsle() {
        return iDIsle;
    }

    public void setIDIsle(Isle iDIsle) {
        this.iDIsle = iDIsle;
    }

    @XmlTransient
    public Collection<Server> getServerCollection() {
        return serverCollection;
    }

    public void setServerCollection(Collection<Server> serverCollection) {
        this.serverCollection = serverCollection;
    }

    @XmlTransient
    public Collection<Storage> getStorageCollection() {
        return storageCollection;
    }

    public void setStorageCollection(Collection<Storage> storageCollection) {
        this.storageCollection = storageCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rack)) {
            return false;
        }
        Rack other = (Rack) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Rack[ id=" + id + " ]";
    }
    
}
